//
//  ScoreView.m
//  Yaniv
//
//  Created by Barak Edry on 3/3/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RunningNumbersView.h"
#import <QuartzCore/QuartzCore.h>


@implementation RunningNumbersView


-(id) initWithFrame:(CGRect)rect{		
	if ((self = [super initWithFrame:rect])){
		animateOnChange = YES;
		score = 0;
		self.text = @"0€";
		self.textAlignment = UITextAlignmentCenter;
		//self.font = [UIFont fontWithName:SCORE_FONT_NAME size:self.frame.size.height -6];
        //self.font = [UIFont fontWithName:SCORE_FONT_NAME size:20];
		self.textColor =[UIColor whiteColor];
		self.adjustsFontSizeToFitWidth = NO;
		self.layer.shadowColor = [UIColor blackColor].CGColor;
		self.layer.shadowOffset = CGSizeMake(-0.55, -1.15);
		self.layer.shadowOpacity = 0.85;
		self.layer.shadowRadius  = 1.5;
		self.layer.masksToBounds = YES;
//		self.backgroundColor = [UIColor darkGrayColor];
//		self.layer.cornerRadius = rect.size.height /2;
//        self.userInteractionEnabled = NO;
	}
	
	return self;
}

-(void)	setValue:(int)newValue{
	
	if (animateOnChange){
		float delay = 0;
		while (_value != newValue) {
			
			if (_value > newValue) {
				_value--;
			} else{
				_value++;
			}
			
			[self performSelector:@selector(setText:) withObject:[NSString stringWithFormat:@"%d", score] afterDelay:delay];
			delay += RUNNING_NUMBERS_DELAY;
		}
		
		[self performSelector:@selector(setText:) withObject:[NSString stringWithFormat:@"%d", score] afterDelay:delay];			
	}else {
		_value = newValue;
		self.text = [NSString stringWithFormat:@"%d", score];
	}

	
	
	//[[Effects class] performSelector:@selector(splashView:) withObject:self afterDelay:delay];
}


@end
